package com.ruoyi.project.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.project.domain.entity.ProjectSale;
import com.ruoyi.project.domain.entity.ProjectStore;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;

@Mapper
public interface ProjectSaleMapper extends BaseMapper<ProjectSale> {
    @Delete("DELETE FROM project_sale")
    void deleteAll();

    @Delete("DELETE FROM project_sale where datas = 'HC2024' ")
    void deleteAllHC2024();

    @Delete("DELETE FROM project_sale where datas = 'HC2022' ")
    void deleteAllHC2022();

    @Delete("DELETE FROM project_sale where datas = 'XXWL2018' ")
    void deleteAllXXWL2018();

    @Delete("DELETE FROM project_sale where datas = 'XXWL' ")
    void deleteAllXXWL();

    @Select("SELECT s.sale_date ,s.goods_id,s.amount ,s.cost_price ,s.cost_total ,s.price ,s.total ,s.profit , g.full_name ,g.name ,g.modal ,g.param , c.company_name \n" +
            "FROM project_sale s\n" +
            "LEFT JOIN project_goods g ON s.goods_id = g.id\n" +
            "LEFT JOIN project_company c ON s.housekeeper_project = c.id\n" +
            "where s.housekeeper_project = #{housekeeperProject} and s.del_flag = '0' order by s.sale_date asc")
    List<ProjectSale> getGjpSale(@Param("housekeeperProject") String housekeeperProject);


    @Select("SELECT s.*, g.full_name ,g.name ,g.modal ,g.param , c.company_name \n" +
            "FROM project_sale s\n" +
            "LEFT JOIN project_goods g ON s.goods_id = g.id\n" +
            "LEFT JOIN project_company c ON s.housekeeper_project = c.id\n" +
            "where s.housekeeper_project = #{housekeeperProject} and s.del_flag = '0' order by s.sale_date asc")
    List<ProjectSale> getAllGjpSale(@Param("housekeeperProject") String housekeeperProject);

    @Select("SELECT s.*, g.full_name, g.name, g.modal, g.param, c.company_name " +
            "FROM project_sale s " +
            "LEFT JOIN project_goods g ON s.goods_id = g.id " +
            "LEFT JOIN project_company c ON s.housekeeper_project = c.id " +
            "WHERE s.housekeeper_project = #{housekeeperProject} and s.del_flag = '0'" +
            "  AND s.sale_date BETWEEN #{startDate} AND #{endDate} " +
            "ORDER BY s.sale_date ASC")
    List<ProjectSale> getAllSaleCustom(@Param("housekeeperProject") String housekeeperProject,
                                       @Param("startDate") Date startDate,
                                       @Param("endDate") Date endDate);
}
